﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Publish_Contact : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    #region validation
    /// <summary>
    /// Using for validate input data on base form
    /// </summary>
    /// <returns></returns>
    private bool validation()
    {
        bool bResult = true;
        if (!reqFullname.IsValid)
            bResult = false;
        if (!reqEmail.IsValid)
            bResult = false;
        if (!reqEmailFormat.IsValid)
            bResult = false;
        if (!reqContent.IsValid)
            bResult = false;
        if (!reqAuthentic.IsValid)
            bResult = false;
        else if (Session["authentic"] == null)
        {
            reqAuthentic.IsValid = false;
            bResult = false;
        }
        else if (txtAuthentic.Text.Trim() != Session["authentic"].ToString())
        {
            reqAuthentic.IsValid = false;
            bResult = false;
        }

        return bResult;
    }
    #endregion validation
    #region fillDO

    private GssDO.DOContact fillDO()
    {
        GssDO.DOContact DO = new GssDO.DOContact();

        DO.PKIDContact = Guid.NewGuid().ToString();
        DO.CreatedDate = DateTime.Now;
        DO.Fullname = txtFullname.Text.Trim();
        DO.Email = txtEmail.Text.Trim();
        DO.Phone = txtPhone.Text.Trim();
        DO.Address = txtAddress.Text.Trim();
        DO.Content = txtContent.Text.Trim();
        DO.IsProcess = 0;
        DO.Level = 0;
        DO.IsDeleted = 0;

        return DO;
    }

    #endregion fillDO
    #region sendContact

    private void sendContact()
    {
        if (validation())
        {
            try
            {
                GssDO.DOContact DO = fillDO();
                GssBL.BLContact BL = new GssBL.BLContact();

                BL.Insert(DO);
                Response.Redirect(@"ContactSuccess.aspx", false);
            }
            catch (Exception exc)
            {
                string mess = exc.Message.ToString();
            }
        }
    }

    #endregion sendContact
    protected void btnSend_ServerClick(object sender, EventArgs e)
    {
        sendContact();
    }
    protected void btnReset_ServerClick(object sender, EventArgs e)
    {
        Response.Redirect(@"Contact.aspx", false);
    }
    protected void btnCancel_ServerClick(object sender, EventArgs e)
    {
        Response.Redirect(@"Default.aspx", false);
    }
}
